import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/serve-publish/application',
    hidden: true,
    meta: { hidden: true }
  },
  {
    path: '/login',
    name: '/login',
    component: () => import('@/views/login'),
    hidden: true,
    meta: { hidden: true }
  },
  // 大数据商城
  {
    path: '/shop-home',
    name: '/shop-home',
    hidden: true,
    component: () => import('@/views/shop/home'),
    meta: { title: '大数据商城', hidden: true }
  },
  // 商城-服务应用
  {
    path: '/shop-app',
    name: '/shop-app',
    hidden: true,
    component: () => import('@/views/shop/data-app'),
    meta: { title: '数据应用', hidden: true }
  },
  {
    path: '/shop-app-detail/:id',
    name: '/shop-app-detail',
    hidden: true,
    component: () => import('@/views/shop/data-app/detail'),
    meta: { title: '数据应用详情', hidden: true }
  },
  {
    path: '/shop-app-subscribe/:id',
    name: '/shop-app-subscribe',
    hidden: true,
    component: () => import('@/views/shop/data-app/subscribe'),
    meta: { title: '数据应用订阅', hidden: true }
  },
  // 商城 服务工具
  {
    path: '/shop-tool',
    name: '/shop-tool',
    hidden: true,
    component: () => import('@/views/shop/data-tool'),
    meta: { title: '数据工具', hidden: true }
  },
  {
    path: '/shop-tool-detail/:id',
    name: '/shop-tool-detail',
    hidden: true,
    component: () => import('@/views/shop/data-tool/detail'),
    meta: { title: '数据工具详情', hidden: true }
  },
  {
    path: '/shop-tool-subscribe/:id',
    name: '/shop-tool-subscribe',
    hidden: true,
    component: () => import('@/views/shop/data-tool/subscribe'),
    meta: { title: '数据工具订阅', hidden: true }
  },
  // 数据服务
  {
    path: '/shop-serve',
    name: '/shop-serve',
    hidden: true,
    component: () => import('@/views/shop/data-serve'),
    meta: { title: '数据服务', hidden: true }
  },
  {
    path: '/shop-serve-subscribe-api/:id',
    name: '/shop-serve-subscribe-api',
    hidden: true,
    component: () => import('@/views/shop/data-serve/subscribe-api'),
    meta: { title: '数据接口订阅', hidden: true }
  },
  {
    path: '/shop-serve-subscribe-database/:id',
    name: '/shop-serve-subscribe-database',
    hidden: true,
    component: () => import('@/views/shop/data-serve/subscribe-database'),
    meta: { title: '数据库表订阅', hidden: true }
  },
  // 服务发布
  {
    name: '/serve-publish',
    path: '/serve-publish',
    component: Layout,
    redirect: '/serve-publish/tool',
    meta: { title: '服务发布管理', icon: 'dashboard' },
    children: [
      {
        path: 'tool',
        name: '/serve-publish/tool',
        component: () => import('@/views/serve-publish/tool'),
        meta: { title: '数据工具发布' }
      },
      {
        path: 'tool-detail/:type?/:id/:auditId?',
        name: '/serve-publish/tool-detail',
        component: () => import('@/views/serve-publish/tool/detail'),
        hidden: true,
        meta: { title: '数据工具详情', hidden: true, hiddenBread: true }
      },
      {
        path: 'application',
        name: '/serve-publish/application',
        component: () => import('@/views/serve-publish/application'),
        meta: { title: '数据应用发布' }
      },
      {
        path: 'app-detail/:type?/:id/:auditId?',
        name: '/serve-publish/app-detail',
        component: () => import('@/views/serve-publish/application/detail'),
        hidden: true,
        meta: { title: '数据应用详情', hidden: true, hiddenBread: true }
      },
      {
        path: 'catalog',
        name: '/serve-publish/catalog',
        component: () => import('@/views/serve-publish/catalog'),
        meta: { title: '数据服务编目' }
      },
      {
        path: 'server-detail/:type?/:id/:auditId?',
        name: '/serve-publish/server-detail',
        component: () => import('@/views/serve-publish/catalog/detail'),
        hidden: true,
        meta: { title: '数据服务发布详情', hidden: true, hiddenBread: true }
      }
    ]
  },
  // 服务审核管理
  {
    name: '/serve-audit',
    path: '/serve-audit',
    component: Layout,
    redirect: '/serve-audit/tool',
    meta: { title: '服务审核管理', icon: 'dashboard' },
    children: [
      {
        path: 'tool',
        name: '/serve-audit/tool',
        component: () => import('@/views/serve-audit/tool'),
        meta: { title: '数据工具审核' }
      },
      {
        path: 'application',
        name: '/serve-audit/application',
        component: () => import('@/views/serve-audit/application'),
        meta: { title: '数据应用审核' }
      },
      {
        path: 'serve',
        name: '/serve-audit/serve',
        component: () => import('@/views/serve-audit/serve'),
        meta: { title: '数据服务审核' }
      }
    ]
  },
  // 服务运营
  {
    name: 'serveOpeManager',
    path: '/serve-ope',
    component: Layout,
    redirect: '/serve-ope/tool',
    meta: { title: '服务运营管理', icon: 'dashboard' },
    children: [
      {
        path: 'analysis',
        name: 'serve-ope-analysis',
        component: () => import('@/views/serve-ope/analysis'),
        meta: { title: '服务运营分析', hiddenBread: true }
      },
      {
        path: 'feedback',
        name: 'serve-ope-feedback',
        component: () => import('@/views/serve-ope/feedback'),
        meta: { title: '问题反馈管理' }
      },
      {
        path: 'appraise',
        name: 'serve-ope-appraise',
        component: () => import('@/views/serve-ope/appraise'),
        meta: { title: '服务评价管理' }
      }
    ]
  },
  // 个人订阅管理
  {
    name: '/personal-subscribe',
    path: '/personal-subscribe',
    component: Layout,
    redirect: '/personal-subscribe/tool',
    meta: { title: '个人订阅管理', icon: 'dashboard' },
    children: [
      {
        path: 'tool',
        name: '/personal-subscribe/tool',
        component: () => import('@/views/personal-subscribe/tool'),
        meta: { title: '数据工具订阅' }
      },
      {
        path: 'application',
        name: '/personal-subscribe/application',
        component: () => import('@/views/personal-subscribe/application'),
        meta: { title: '数据应用订阅' }
      },
      {
        path: 'serve',
        name: '/personal-subscribe/serve',
        component: () => import('@/views/personal-subscribe/serve'),
        meta: { title: '数据服务订阅' }
      }
    ]
  },
  // 数据管理
  {
    name: 'dataManager',
    path: '/data',
    component: Layout,
    redirect: '/data/aggregation',
    meta: { title: '数据管理', icon: 'dashboard' },
    children: [
      {
        path: 'alarm-view',
        name: 'data-alarm-view',
        component: () => import('@/views/data/alarm-view'),
        meta: { title: '告警总览', hiddenBread: true }
      },
      {
        path: 'alarm-detail',
        name: 'data-alarm-detail',
        component: () => import('@/views/data/alarm-detail'),
        meta: { title: '告警详情', hiddenBread: true }
      },
      {
        path: 'data-detail',
        name: 'data-data-detail',
        component: () => import('@/views/data/data-detail'),
        meta: { title: '数据标准信息' }
      },
      {
        path: 'aggregation',
        name: 'data-aggregation',
        component: () => import('@/views/data/aggregation'),
        meta: { title: '数据汇聚作业' }
      },
      {
        path: 'bus-metric',
        name: 'data-bus-metric',
        component: () => import('@/views/data/bus-metric'),
        meta: { title: '业务指标监控' }
      },
      {
        path: 'quality-work',
        name: 'data-quality-work',
        component: () => import('@/views/data/quality-work'),
        meta: { title: '数据质量作业' }
      },
      {
        path: 'dev-work',
        name: 'data-dev-work',
        component: () => import('@/views/data/dev-work'),
        meta: { title: '数据开发作业' }
      },
      {
        path: 'quality-report',
        name: 'data-quality-report',
        component: () => import('@/views/data/quality-report'),
        meta: { title: '数据质量作业' }
      },
      {
        path: 'serve-detail',
        name: 'data-serve-detail',
        component: () => import('@/views/data/serve-detail'),
        meta: { title: '数据服务详情' }
      }
    ]
  },
  // 数据考核分析
  {
    name: 'dataReport',
    path: '/data-report',
    component: Layout,
    redirect: '/data-report/aggregation',
    meta: { title: '数据报表管理', icon: 'dashboard' },
    children: [
      {
        path: 'check-analysis',
        name: 'data-report-check-analysis',
        component: () => import('@/views/data-report/check-analysis'),
        meta: { title: '考核分析', hiddenBread: true }
      },
      {
        path: 'alarm-analysis',
        name: 'data-report-alarm-analysis',
        component: () => import('@/views/data-report/alarm-analysis'),
        meta: { title: '告警分析', hiddenBread: true }
      },
      {
        path: 'res-monitor',
        name: 'data-report-res-monitor',
        component: () => import('@/views/data-report/res-monitor'),
        meta: { title: '资源运行监控', hiddenBread: true }
      },
      {
        path: 'serve',
        name: 'data-report-serve',
        component: () => import('@/views/data-report/serve'),
        meta: { title: '数据服务', hiddenBread: true }
      },
      {
        path: 'data-based',
        name: 'data-report-data-based',
        component: () => import('@/views/data-report/data-based'),
        meta: { title: '数据治理', hiddenBread: true }
      },
      {
        path: 'data-lake',
        name: 'data-report-data-lake',
        component: () => import('@/views/data-report/data-lake'),
        meta: { title: '数据湖', hiddenBread: true }
      },
      {
        path: 'data-aggregation',
        name: 'data-report-data-aggregation',
        component: () => import('@/views/data-report/data-aggregation'),
        meta: { title: '数据汇聚', hiddenBread: true }
      }
    ]
  },
  // 知识库
  {
    name: 'dataKnowledge',
    path: '/data-knowledge',
    component: Layout,
    meta: { title: '知识库', icon: 'dashboard' },
    children: [
      {
        name: 'dataKnowledgeIndex',
        path: 'index',
        meta: { title: '知识库', icon: 'dashboard', hiddenBread: true },
        component: () => import('@/views/data/knowledge')
      }
    ]
  },
  // 系统设置
  {
    name: '/system',
    path: '/system',
    component: Layout,
    meta: { title: '统一后台', icon: 'dashboard' },
    children: [
      {
        name: '/system/user',
        path: 'user',
        meta: { title: '用户管理' },
        component: () => import('@/views/system/user')
      },
      {
        name: '/system/role',
        path: 'role',
        meta: { title: '角色管理' },
        component: () => import('@/views/system/role')
      },
      {
        name: '/system/permission',
        path: 'permission',
        meta: { title: '资源管理' },
        component: () => import('@/views/system/permission')
      },
      {
        name: '/system/department',
        path: 'department',
        meta: { title: '组织管理' },
        component: () => import('@/views/system/department')
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
